/*******************************************************************************
* Project: QSAR(Cute Software Architecture) 
*
* Copyright: Copyright(C) 2024 by YuetingBen, All Rights Reserved
*
* File name: DemCfg.h
*
* Brief: ;
*
* Author: Yueting.Ben
*
* Module: Dem
*
*******************************************************************************/

#ifndef DEMCFG_H
#define DEMCFG_H

/** HEADER FILES **/
#include "DemType.h"
#include "DemRte.h" 


/** MACRO DEFINITION **/
#define DemDataElementConfig_Voltage                    0u
#define DemDataElementConfig_Odometer                   1u
#define DemDataElementConfig_SnapshotTestValue         2u
#define DemDataElementConfig_FaultCounter               3u
#define DemDataElementConfig_ExtendedTestValue         4u
#define DemDataElementConfig_Max                        5u

#define DTCSnapshotIdentification_SnapshotRecord01_Max 3u
#define DTCSnapshotIdentification_SnapshotRecord02_Max 1u

#define DTCSnapshotIdentification_SnapshotRecord01_Index 0u
#define DTCSnapshotIdentification_SnapshotRecord02_Index 1u
#define DemFreezeFrameRecordNumber_Max 2u

#define DTCExtendedDataRecordNumber_ExtendedDataRecord01_Max 2u
#define DTCExtendedDataRecordNumber_ExtendedDataRecord02_Max 1u
#define DTCExtendedDataRecordNumber_Max 2u


#define DEM_TRIGGER_ON_CONFIRMED (0u)
#define DEM_TRIGGER_ON_EVERY_TEST_FAILED (1u)
#define DEM_TRIGGER_ON_FDC_THRESHOLD (2u)
#define DEM_TRIGGER_ON_PENDING  (3u)
#define DEM_TRIGGER_ON_TEST_FAILED (4u)
#define DEM_TRIGGER_ON_TEST_FAILED_THIS_OPERATION_CYCLE (5u)

#define DEM_UPDATE_RECORD_NO (0u)
#define DEM_UPDATE_RECORD_YES (1u)

#define DEM_CFG_COUNTER_INCREMENT_STEP_SIZE(eventParameterConfigPtr) (eventParameterConfigPtr->debounceAlgorithmClass.counterBased.counterBasedClassRef->incrementStepSize)
#define DEM_CFG_COUNTER_DECREMENT_STEP_SIZE(eventParameterConfigPtr) (eventParameterConfigPtr->debounceAlgorithmClass.counterBased.counterBasedClassRef->decrementStepSize)
#define DEM_CFG_COUNTER_FAILED_THRESHOLD(eventParameterConfigPtr) (eventParameterConfigPtr->debounceAlgorithmClass.counterBased.counterBasedClassRef->failedThreshold)
#define DEM_CFG_COUNTER_PASSED_THRESHOLD(eventParameterConfigPtr) (eventParameterConfigPtr->debounceAlgorithmClass.counterBased.counterBasedClassRef->passedThreshold)
#define DEM_CFG_COUNTER_JUMPUP(eventParameterConfigPtr) (eventParameterConfigPtr->debounceAlgorithmClass.counterBased.counterBasedClassRef->jumpUp)
#define DEM_CFG_COUNTER_JUMPDOWN(eventParameterConfigPtr) (eventParameterConfigPtr->debounceAlgorithmClass.counterBased.counterBasedClassRef->jumpDown)
#define DEM_CFG_COUNTER_JUMPUP_VALUE(eventParameterConfigPtr) (eventParameterConfigPtr->debounceAlgorithmClass.counterBased.counterBasedClassRef->jumpDownValue)
#define DEM_CFG_COUNTER_JUMPDOWN_VALUE(eventParameterConfigPtr) (eventParameterConfigPtr->debounceAlgorithmClass.counterBased.counterBasedClassRef->jumpDownValue)
#define DEM_CFG_COUNTER_BEHAVIOR(eventParameterConfigPtr) (eventParameterConfigPtr->debounceAlgorithmClass.counterBased.counterBasedClassRef->behavior)
#define DEM_CFG_COUNTER_STORAGE(eventParameterConfigPtr) (eventParameterConfigPtr->debounceAlgorithmClass.counterBased.counterBasedClassRef->storage)
#define DEM_CFG_COUNTER_FDC_THRESHOLD_STORAGE_VALUE(eventParameterConfigPtr) (eventParameterConfigPtr->debounceAlgorithmClass.counterBased.counterBasedClassRef->fdcThresholdStorageValue)


/** TYPEDEF DEFINITION **/
typedef struct
{
    uint16 DemNvRamBlockIdRef;
}DemNvRamBlockIdType;

typedef struct
{
    uint8 DemOperationCycleId; /* DemOperationCycleId */
}DemOperationCycleType;


typedef struct
{
    uint8 DemDataElementDataSize;
}DemInternalDataElementClassType;

typedef  Std_ReturnType (*Dem_GetExtendedDataRecordType)(
    Dem_DtcNvmDataType* DtcNvmDataPtr,
    uint8 BufSize,
    uint8* DestBuffer
);

typedef struct
{
    uint8 DemDataElementArraySize;
    Dem_GetExtendedDataRecordType DemDataElementReadFnc;
}DemExternalCSDataElementClassType;


typedef struct
{
    DemExternalCSDataElementClassType DemExternalCSDataElementClass;
}DemDataElementClassType;


typedef struct
{
    uint16 DemDidIdentifier; /* DemDidIdentifier */
    DemDataElementClassType* DemDidDataElementClassRef; /* DemDidDataElementClassRef */
    uint8 DemDidDataElementClassRefIndexMax;
}DemDidClassType;

typedef struct
{
    DemDidClassType* DemDidClassRef; /* DemDidClassRef */
    uint8 DemDidClassRefIndexMax;
}DemFreezeFrameClassType;


typedef uint8 DemFreezeFrameRecordTriggerType;

typedef uint8 DemFreezeFrameRecordUpdateType;

typedef struct
{
    uint8 DemFreezeFrameRecordNumber; /* DemFreezeFrameRecordNumber */
    DemFreezeFrameRecordTriggerType DemFreezeFrameRecordTrigger; /* DemFreezeFrameRecordTrigger */
    DemFreezeFrameRecordUpdateType DemFreezeFrameRecordUpdate; /* DemFreezeFrameRecordUpdate */
}DemFreezeFrameRecordClassType;

typedef struct
{
    DemFreezeFrameRecordClassType* freezeFrameRecordClassRef[DemFreezeFrameRecordNumber_Max]; /* DemFreezeFrameRecordClassRef */
}DemFreezeFrameRecNumClassType;

typedef uint8 Dem_ExtendedDataRecordTriggerType;

typedef uint8 Dem_ExtendedDataRecordUpdateType;

typedef struct
{
    DemDataElementClassType* DemDataElementClassRef; /* DemDataElementClassRef */
    uint8 DemDataElementClassRefIndexMax; /* DemDataElementClassRefIndex */
    uint8 DemExtendedDataRecordNumber; /* DemExtendedDataRecordNumber */
    Dem_ExtendedDataRecordTriggerType DemExtendedDataRecordTrigger; /* DemExtendedDataRecordTrigger */
    Dem_ExtendedDataRecordUpdateType DemExtendedDataRecordUpdate; /* DemExtendedDataRecordUpdate */
}DemExtendedDataRecordClassType;

typedef struct
{
    DemExtendedDataRecordClassType* DemExtendedDataRecordClassRef; /* DemExtendedDataRecordClassRef */
}DemExtendedDataClassType;

typedef uint8 Dem_DTCSignificanceType;
#define DEM_EVENT_SIGNIFICANCE_FAULT ((Dem_DTCSignificanceType)(0u))
#define DEM_EVENT_SIGNIFICANCE_OCCURRENCE ((Dem_DTCSignificanceType)(1u))

typedef struct
{
    DemExtendedDataClassType* DemExtendedDataClassRef;/* DemExtendedDataClassRef */
    DemFreezeFrameRecNumClassType* DemFreezeFrameRecNumClassRef; /* DemFreezeFrameRecNumClassRef */
    DemFreezeFrameClassType* DemFreezeFrameClassRef; /* DemFreezeFrameClassRef */
    uint8 DemMaxNumberExtendedDataRecords;/* DemMaxNumberExtendedDataRecords */
    uint8 DemMaxNumberFreezeFrameRecords;/* DemMaxNumberFreezeFrameRecords */
    uint8 DemAgingCycleCounterThreshold;/* DemAgingCycleCounterThreshold */
    uint8 DemAgingCycleCounterThresholdForTFSLC; /* DemAgingCycleCounterThresholdForTFSLC */
    uint8 dtcPriority;
    Dem_DTCSignificanceType DemDTCSignificance;/* DemDTCSignificance */
}Dem_DTCAttributesType;


typedef uint8 Dem_NvStorageStrategyType;
#define DEM_NV_STORAGE_DURING_SHUTDOWN ((Dem_NvStorageStrategyType)(0u))
#define DEM_NV_STORAGE_IMMEDIATE_AT_FIRST_OCCURRENCE ((Dem_NvStorageStrategyType)(1u))

typedef uint8 DemDTCSeverityType;
#define DEM_SEVERITY_NO_SEVERITY ((DemDTCSeverityType)(0u))
#define DEM_SEVERITY_MAINTENANCE_ONLY ((DemDTCSeverityType)(1u))
#define DEM_SEVERITY_CHECK_AT_NEXT_HALT ((DemDTCSeverityType)(2u))
#define DEM_SEVERITY_CHECK_IMMEDIATELY ((DemDTCSeverityType)(3u))


typedef struct
{
    uint32 dtcValue; /* DemDtcValue */
    Dem_DTCAttributesType* dtcAttributesRef;/* DemDTCAttributesRef */
    DemDTCSeverityType dtcSeverity;/* DemDTCSeverity */
    Dem_NvStorageStrategyType nvStorageStrategy; /* DemNvStorageStrategy */
}Dem_DTCType;


typedef uint8 DemEventKindType;
#define DEM_EVENT_KIND_SWC ((DemEventKindType)(0u))
#define DEM_EVENT_KIND_BSW ((DemEventKindType)(1u))

typedef uint8 Dem_DebounceBehaviorType;
#define DEM_DEBOUNCE_FREEZE ((Dem_DebounceBehaviorType)(0u))
#define DEM_DEBOUNCE_RESET ((Dem_DebounceBehaviorType)(1u))

typedef struct
{
    uint16 failedThreshold; /* DemDebounceTimeFailedThreshold */
    uint16 passedThreshold; /* DemDebounceTimePassedThreshold */
    Dem_DebounceBehaviorType behavior; /* DemDebounceBehavior */
    uint16 fdcThresholdStorageValue; /* DemTimeBasedFdcThresholdStorageValue */
}Dem_DebounceTimeBasedClassType;

typedef struct
{
    Dem_DebounceTimeBasedClassType* timeBasedClassRef; /* DemDebounceTimeBasedClassRef */
}Dem_DebounceTimeBasedType;


typedef struct
{
    uint16 incrementStepSize; /* DemDebounceCounterIncrementStepSize */
    uint16 decrementStepSize; /* DemDebounceCounterDecrementStepSize */
    sint16 failedThreshold; /* DemDebounceCounterFailedThreshold */
    sint16 passedThreshold; /* DemDebounceCounterPassedThreshold */
    boolean jumpUp; /* DemDebounceCounterJumpUp */
    boolean jumpDown; /* DemDebounceCounterJumpDown */
    sint16 jumpDownValue; /* DemDebounceCounterJumpDownValue */
    sint16 jumpUpValue; /* DemDebounceCounterJumpUpValue */
    Dem_DebounceBehaviorType behavior; /* DemDebounceBehavior */
    boolean storage; /* DemDebounceCounterStorage */
    uint16 fdcThresholdStorageValue; /* DemCounterBasedFdcThresholdStorageValue */
}Dem_DebounceCounterBasedClassType;

typedef struct
{
    Dem_DebounceCounterBasedClassType* counterBasedClassRef; /* DemDebounceCounterBasedClassRef */
}Dem_DebounceCounterBasedType;


typedef struct
{
    Dem_DebounceTimeBasedType timeBased; /* DemDebounceTimeBased */
    Dem_DebounceCounterBasedType counterBased; /* DemDebounceCounterBased */
}Dem_DebounceAlgorithmClassType; 

typedef struct
{
    Dem_EventIdType eventId; /* DemEventId */
    DemEventKindType eventKind; /* DemEventKind */
    Dem_DTCType*  dtcRef; /* DemDTCRef */
    uint8 confirmationThreshold; /* DemEventConfirmationThreshold */
    DemOperationCycleType* operationCycleRef; /* DemOperationCycleRef */
    Dem_DebounceAlgorithmClassType debounceAlgorithmClass;/* DemDebounceAlgorithmClass */
}Dem_EventParameterType;


typedef uint8 Dem_DtcStatusAvailabilityMaskType;

typedef struct
{
    Dem_DtcStatusAvailabilityMaskType DemDtcStatusAvailabilityMask; /* DemDtcStatusAvailabilityMask */
}Dem_PrimaryMemoryType;

typedef struct
{
    Dem_PrimaryMemoryType DemPrimaryMemory;
}Dem_EventMemorySetType;


/** LOCAL FUNCTION DECLARATION **/
Std_ReturnType Dem_GetElementDataVoltage(
    Dem_DtcNvmDataType* DtcNvmDataPtr,
    uint8 BufSize,
    uint8* DestBuffer
);

Std_ReturnType Dem_GetElementDataOdometer(
    Dem_DtcNvmDataType* DtcNvmDataPtr,
    uint8 BufSize,
    uint8* DestBuffer
);

Std_ReturnType Dem_GetElementDataSnapshotTestValue(
    Dem_DtcNvmDataType* DtcNvmDataPtr,
    uint8 BufSize,
    uint8* DestBuffer
);

Std_ReturnType Dem_GetElementDataFaultDetectionCounter(
    Dem_DtcNvmDataType* DtcNvmDataPtr,
    uint8 BufSize,
    uint8* DestBuffer
);

Std_ReturnType Dem_GetElementDataAgingCounter(
    Dem_DtcNvmDataType* DtcNvmDataPtr,
    uint8 BufSize,
    uint8* DestBuffer
);

Std_ReturnType Dem_GetElementDataAgedCounter(
    Dem_DtcNvmDataType* DtcNvmDataPtr,
    uint8 BufSize,
    uint8* DestBuffer
);

Std_ReturnType Dem_GetElementDataExtendedTestValue(
    Dem_DtcNvmDataType* DtcNvmDataPtr,
    uint8 BufSize,
    uint8* DestBuffer
);

/** LOCAL DATA DEFINITION **/
extern const DemNvRamBlockIdType DemNvRamBlockIdMapTable[DemConf_NvmBlockId_Max];
extern const Dem_EventParameterType Dem_EventParameterConfig[DemConf_DemEventId_Max];

extern const Dem_EventMemorySetType Dem_EventMemorySetConfig[1u];

#endif
